package com.microcity.cleanjava.mvvm.ui.map.activity;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;

import com.darksider.basemodule.base.originbase.OriginBaseActivity;
import com.darksider.basemodule.di.Injectable;
import com.microcity.cleanjava.R;
import com.microcity.cleanjava.databinding.ActivityMainBinding;
import com.microcity.cleanjava.di.ActivityModule;
import com.microcity.cleanjava.mvvm.ui.weight.MovingImageView;
import com.microcity.cleanjava.mvvm.ui.weight.MovingViewAnimator.MovingState;
import com.microcity.cleanjava.mvvm.viewmodel.UserViewModel;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 实现Injectable以实现Activity自动注入,
 * 实现HasSupportFragmentInjector以实现Fragment自动注入，Fragment注入还需要{@link ActivityModule}
 */
public class MainActivity extends OriginBaseActivity<ActivityMainBinding, UserViewModel> implements Injectable{

    private MovingImageView mivMenu;
    private CircleImageView civHead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //将ViewModel延迟到子类中，如果不使用可以选在不获取ViewModel,而且在子类中实现此处代码获取ViewModel的Class时，获取不到，
        mViewModel = ViewModelProviders.of(this, mViewModelFactory).get(UserViewModel.class);
        //去除所有动画
//        mBinding.navMain.enableAnimation(false);
        //有点缩放动画
        mBinding.navMain.enableItemShiftingMode(false);
        mBinding.navMain.enableShiftingMode(false);
        mivMenu = mBinding.nvMenu.getHeaderView(0).findViewById(R.id.miv_menu);
        civHead = mBinding.nvMenu.getHeaderView(0).findViewById(R.id.civ_head);
        mBinding.dlMainRoot.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                mivMenu.pauseMoving();
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                if (mivMenu.getMovingState() == MovingState.stop) {
                    mivMenu.startMoving();
                } else if (mivMenu.getMovingState() == MovingState.pause) {
                    mivMenu.resumeMoving();
                }
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                mivMenu.stopMoving();
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                if (mivMenu.getMovingState() == MovingState.stop) {
                    mivMenu.startMoving();
                } else if (mivMenu.getMovingState() == MovingState.pause) {
                    mivMenu.resumeMoving();
                }
            }
        });
    }


    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }

    @Override
    public boolean isUseDataBinding() {
        return true;
    }
}
